﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CategoryIndex.aspx.cs"
    Inherits="ZLCMS.Web.SystemManage.Basics.ProductCategory.CategoryIndex" %>
    <%@ Register src="~/SystemManage/Control/SinglePictureControl.ascx" tagname="SinglePictureControl" tagprefix="spc" %>
    <%@ Register src="~/SystemManage/Control/JFileControl.ascx" tagname="JFileControl" tagprefix="uc1" %>

<div class="pageContent">
    <div class="panelBar">
        <ul class="toolBar">
            <li><a class="icon" href="javascript:void(0)" onclick="navTab.reload();" title="刷新目录">
                <span>刷新目录</span></a></li>
        </ul>
    </div>
    <div class="unitBox" style="float: left; display: block; overflow: auto; width: 358px;">
        <div class="pageHeader" style="border: 1px #B8D0D6 solid">
            <div class="searchBar">
                <table class="searchContent" width="100%">
                    <tr>
                        <td width="300px">
                            <h3>
                                产品目录</h3>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="pageContent" style="border: 1px #B8D0D6 solid;" layouth="70">
            <div class="pageFormContent" layouth="128">
                <ul class="ztree" id="productcategroy_tree" setting='
{
	view: {
		addHoverDom: addHoverDom,
		removeHoverDom: removeHoverDom,
		selectedMulti: false
	},
    data: {
		key: {
			name: "CategoryName"
		},
		simpleData: {
			enable: true,
			idKey: "Id",
			pIdKey: "ParentId"
		},
		keep: {
			parent: false,
			leaf: false
		}
	},
	async: {
		enable: true,
		type: "post",
		url: "/SystemManage/Basics/ProductCategory/CategoryInterface.aspx?opt=load_data",
        otherParam: ["temp", new Date().valueOf()]
	},
    edit: {
		enable: true,
		editNameSelectAll: false,
		showRemoveBtn: true,
		showRenameBtn: false,
		removeTitle: "删除",
		renameTitle: "修改"
	},
	callback: {
		beforeDrag: function (treeId, treeNodes) {
			return false;
		},
        onAsyncSuccess:function(event, treeId, treeNode, msg){
            $.fn.zTree.getZTreeObj(treeId).expandAll(true);
        },
        beforeRename: function(treeId, treeNode, newName, isCancel){
            
            $.get("/SystemManage/Basics/ProductCategory/CategoryInterface.aspx", {opt:"update", CategoryName:newName, ParentId:treeNode.ParentId, Id:treeNode.Id, temp:new Date().valueOf()}, function(data){
                var obj=$.parseJSON(data);
                treeNode.ItemText = obj.ItemText;
                $.fn.zTree.getZTreeObj(treeId).updateNode(treeNode);
                alertMsg.correct("操作成功");
            });
            return true;
        },
        beforeRemove:function(treeId, treeNode){
            alertMsg.confirm("请确认删除当前分类项", {
                okCall: function() {
                    $.get("/SystemManage/Basics/ProductCategory/CategoryInterface.aspx", {opt:"remove", Id:treeNode.Id, temp:new Date().valueOf()}, function(data){
                        $.fn.zTree.getZTreeObj(treeId).removeChildNodes(treeNode);
                        $.fn.zTree.getZTreeObj(treeId).removeNode(treeNode);
                        alertMsg.correct("操作成功");
                    }); 
                }
            });
            return false;
        },
        onClick:function(event, treeId, treeNode, clickFlag){
        $("#font_category_id",navTab.getCurrentPanel()).html(treeNode.Id);
            $("#Id",navTab.getCurrentPanel()).val(treeNode.Id);
            $("#Name",navTab.getCurrentPanel()).val(treeNode.CategoryName);
            $("#Sort",navTab.getCurrentPanel()).val(treeNode.Sort);
            $("#ShortDesc",navTab.getCurrentPanel()).val(treeNode.ShortDesc);
          try{
            var imgUrlObj=$.parseJSON(treeNode.ImgUrl);
            if(imgUrlObj){
              $(".image").css("margin-top","0px");
              $(".image",navTab.getCurrentPanel()).first().attr("src",imgUrlObj[0].FilePath);
              
            }
            else{
               $(".image").first().attr("src","");
            }
            $("#fc_open_value_json", navTab.getCurrentPanel()).val(treeNode.ImgUrl);
            if(treeNode.AttachmentUrl){
            $("#fc_relatedimgsContainer div.jFileControl", navTab.getCurrentPanel()).attr("json_data",treeNode.AttachmentUrl);
            $("#fc_relatedimgs_grid_json", navTab.getCurrentPanel()).val(treeNode.AttachmentUrl);
            //flushGridList(treeNode.AttachmentUrl);
                initLayout();
                initUI($("#fc_relatedimgsContainer", navTab.getCurrentPanel()));

           }else{
              clearGridList();
           $("#fc_relatedimgs_grid_json", navTab.getCurrentPanel()).val();
           }
           }catch(e){}
            
            $("#IsActive").attr("checked", (treeNode.IsActive == "1"));
            $("#IsHot").attr("checked", (treeNode.IsHot == "1"));
            loadSkuAndSearchPropItem(treeNode.Id);
            _currentNode = treeNode;
        }
	}
}
' />
            </div>
<%--            <div class="formBar">
                <ul>
                    <li>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button onclick="addItem('productcategroy_tree')" type="button">
                                    添加目录</button></div>
                        </div>
                    </li>
                </ul>
            </div>--%>
            <script type="text/javascript">
                var _currentNode = {};
                function addItem(treeId, parentNode) {
                    var pid = 0;
                    if (parentNode) {
                        pid = parentNode.Id;
                    }
                    $.get("/SystemManage/Basics/ProductCategory/CategoryInterface.aspx", { opt: "add", CategoryName: "新的目录", ParentId: pid, temp: new Date().valueOf() }, function (data) {
                        var zTree = $.fn.zTree.getZTreeObj(treeId);
                        if (parentNode) {
                            zTree.addNodes(parentNode, $.parseJSON(data));
                        } else {
                            zTree.addNodes(null, $.parseJSON(data));
                        }
                    });
                }

                function addHoverDom(treeId, treeNode) {
                    var sObj = $("#" + treeNode.tId + "_span");
                    if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
                    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
				+ "' title='增加子目录' onfocus='this.blur();'></span>";
                    sObj.after(addStr);
                    var btn = $("#addBtn_" + treeNode.tId);
                    if (btn) btn.bind("click", function () {
                        addItem(treeId, treeNode);
                        return false;
                    });
                };
                function removeHoverDom(treeId, treeNode) {
                    $("#addBtn_" + treeNode.tId).unbind().remove();
                };
                function deleteSKU(id) {
                    $.ajax({
                        url: '/SystemManage/Basics/ProductSKU/SKUGroupDelete.aspx?uid=' + id,
                        success: function () {
                            $('#dl_sku_' + id).remove();
                           //$('#sku_title_' + id).remove();
                          //  $('#sku_operation_' + id).remove();
                        }
                    });
                }

                function deleteCategoryProperty(id) {
                    $("#dl_search_property_item").ExecuteCommand({
                    successCallBack: function (result) {
                        $('#dl_search_property_item_' + id).remove();
                        },
                        errorCallback: function (errorCode, msg) {
                            alert(msg);
                        }
                    }, 'User.DeleteSearchProperty', { Id: parseInt(id) });

                }
                
                function loadSkuAndSearchPropItem(id) {
                    //获取sku项 --begin
                    //加载父节点分类sku项
                    $('#sku_groups').html("");
                    $("#sku_groups").ExecuteCommand({
                        successCallBack: function (skuresult) {
                            if (skuresult) {
                                if (skuresult.List.length > 0) {
                                    var skuGroups = skuresult.List;   
                                    str = "";
                                    for (var key in skuGroups) {
                                        str += " <dl class='nowrap'><dt style=\"background: #F5F5F5;color: #6F6F6F;\" id='sku_title_" + skuGroups[key].Id + "'>" + skuGroups[key].PrivateName + "</dt><dd style='background: #F5F5F5;color:#fff;'><span>修改</span> <span>删除</span></dd></dl>";
                                      $('#sku_groups').html($('#sku_groups').html() + str);
                                    }
                                }
                           
                            }
                            // $("#sku_groups").attr('loading_command', '0');
                            //加载子节点分类sku项
                            ////////////////////////////////////////////////////////////////////////
                            $("#sku_groups").ExecuteCommand({
                                successCallBack: function (sonskuresult) {
                                    if (sonskuresult) {
                                        if (sonskuresult.List.length > 0) {
                                            var sonSkuGroups = sonskuresult.List;
                                            str = "";
                                            for (var key in sonSkuGroups) {
                                                str += "<dl class='nowrap' id='dl_sku_" + sonSkuGroups[key].Id + "'><dt id='sku_title_" + sonSkuGroups[key].Id + "'>" + sonSkuGroups[key].PrivateName + "</dt>" +
                    "<dd id='sku_operation_" + sonSkuGroups[key].Id + "'>" +
                        '<a href="javascript:navTab.openTab(\'EditSearchPropertyItem\',\'/SystemManage/Basics/ProductSKU/SKUGroupEdit.aspx?uid=' + sonSkuGroups[key].Id + '\',{title:\'编辑SKU\'});" title="SKU项-修改"><span>修改</span></a> <a href="javascript:deleteSKU(' + sonSkuGroups[key].Id + ');"' +
                            'title="SKU项-删除"><span>删除</span></a>' +
                    "</dd></dl>";
                                            }
   $('#sku_groups').html($('#sku_groups').html() + str);
                                        }
                                    }
                                },
                                errorCallback: function (errorCode, msg) {
                                    alert(msg);
                                }
                            }, 'User.LoadSkuGroup', { CategoryId: id });
                        },
                        errorCallback: function (errorCode, msg) {
                            alert(msg);
                        }
                    }, 'User.LoadSkuGroup', { CategoryId: id, Opt: "get_parent" });

                    //获取sku项 --end

                    //获取搜索属性项 --begin
                    $('#dl_search_property_item').html("");
                    $("#dl_search_property_item").ExecuteCommand({
                        successCallBack: function (propertyresult) {
                            if (propertyresult) {
                                if (propertyresult.List.length > 0) {
                                    var propertyGroups = propertyresult.List;
                                    str = "";
                                    for (var key in propertyGroups) {
                                        str += " <dl class='nowrap'><dt style=\"background: #F5F5F5;color: #6F6F6F;\" id='sku_title_" + propertyGroups[key].Id + "'>" + propertyGroups[key].PropertyValue + "</dt><dd style='background: #F5F5F5;color:#fff;'><span>修改</span> <span>删除</span></dd></dl>";
                                    }
                                    $('#dl_search_property_item').html($('#dl_search_property_item').html() + str);
                                }
                            }
                            // $("#dl_search_property_item").attr('loading_command', '0');
                            //加载子节点分类sku项
                            ////////////////////////////////////////////////////////////////////////
                            $("#dl_search_property_item").ExecuteCommand({
                                successCallBack: function (sonpropertyresult) {
                                    if (sonpropertyresult) {
                                        if (sonpropertyresult.List.length > 0) {
                                            var propertyGroups = sonpropertyresult.List;
                                            str = "";
                                            for (var key in propertyGroups) {
                                                str += "<dl class='nowrap' id='dl_search_property_item_" + propertyGroups[key].Id + "'><dt id='search_property_item_title_" + propertyGroups[key].Id + "'>" + propertyGroups[key].PropertyValue + "</dt>" +
                    "<dd id='search_property_item_operation_" + propertyGroups[key].Id + "'>" +
                        '<a href="javascript:navTab.openTab(\'edit_search_property\',\'/SystemManage/Basics/SearchProperty/SearchPropertyEdit.aspx?cid=' + propertyGroups[key].CategoryId + '&uid=' + propertyGroups[key].Id + '\',{title:\'编辑分类搜索属性\'});" title="分类搜索属性项-修改"><span>修改</span></a> <a href="javascript:deleteCategoryProperty(' + propertyGroups[key].Id + ');"' +
                            'title="分类属性搜索项-删除"><span>删除</span></a>' +
                    "</dd></dl>";
                                            }
                                            $('#dl_search_property_item').html($('#dl_search_property_item').html() + str);
                                        }
                                    }
                                },
                                errorCallback: function (errorCode, msg) {
                                    alert(msg);
                                }
                            }, 'User.LoadSearchProperty', { CategoryId: id });
                            //////////////////////////
                        },
                        errorCallback: function (errorCode, msg) {
                            alert(msg);
                        }
                    }, 'User.LoadSearchProperty', { CategoryId: id, Opt: "get_parent" });

                    //获取搜索属性项 --end
                }


                $(".sku").click(function () {
                    var Id = $("#Id").val();
                    if (Id > 0)
                        navTab.openTab('add_SKU_group','/SystemManage/Basics/ProductSKU/SKUGroupEdit.aspx?Kind=SKU&cid=' + Id,{title:'订制SKU属性'});
                });

                $("#a_add_search_property").click(function () {
                    var Id = $("#Id").val();
                    if (Id > 0)
                        navTab.openTab('EditSearchPropertyItem', '/SystemManage/Basics/SearchProperty/SearchPropertyEdit.aspx?cid=' + Id, { title: '订制分类搜索属性' });
                });
            </script>
        </div>
    </div>
    <div class="unitBox" style="margin-left: 360px;">
        <div class="pageHeader" style="border: 1px #B8D0D6 solid">
            <div class="searchBar">
                <table class="searchContent">
                    <tr>
                        <td>
                            <h3>
                                详细设置</h3>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="pageContent" style="border: 1px #B8D0D6 solid;" layouth="70">
            <div class="pageFormContent" layouth="128">
            <dl class="nowrap">
                    <dt>分类ID：</dt>
                    <dd>
                   <font id="font_category_id"></font>
                </dl>
                <dl class="nowrap">
                    <dt>名称：</dt>
                    <dd>
                        <input id="Name" type="text" /></dd>
                </dl>
                <dl class="nowrap">
                    <dt>目录排序：</dt>
                    <dd>
                        <input id="Sort" type="text" /></dd>
                </dl>
                <dl class="nowrap">
                    <dt>是否有效：</dt>
                    <dd>
                        <input id="IsActive" type="checkbox" /></dd>
                </dl>
                <dl class="nowrap">
                    <dt>是否推荐：</dt>
                    <dd>
                        <input id="IsHot" type="checkbox" /></dd>
                </dl>
       <dl class="nowrap">
            <dt>产品分类图片：</dt>
            <dd>（支持JPG、PNG格式，较好的效果为200*200）</dd>
        </dl>
        <dl class="nowrap">
            <dt>&nbsp;</dt>
            <dd>   <spc:SinglePictureControl ID="fc_open" runat="server" ImageWidth="200" ImageHeight="200"
                    FileCountLimit="1" FileFilters="*.jpg;*.jpeg;*.bmp;*.png;*.gif" FileDesc="图片" /></dd>
        </dl>
        <dl class="nowrap" style="display:none">
            <dt>轮播多图：</dt>
            <dd>（支持JPG、PNG格式，较好的效果为200*200）</dd>
        </dl>
          <dl class="nowrap"  id="fc_relatedimgsContainer" style="display:none">
            <dt>&nbsp;</dt>
            <dd>
            <uc1:JFileControl id= "fc_relatedimgs" runat= "Server" MaxFiles="5" FileType="jpg|png|jpeg|gif" AllowDelete="true" Enable="true" IsShowHistory="true"/>
             </dd>
        </dl>

          <dl class="nowrap">
                    <dt>简介：</dt>
                    <dd>
                     <textarea class="editor" name="ShortDesc" rows="10" cols="60" style="100%" id="ShortDesc" runat="Server"
                    uplinkurl="/SystemManage/Common/ContentUpload.aspx?dir=doc&ext=zip,rar,txt" uplinkext="zip,rar,txt"
                    upimgurl="/SystemManage/Common/ContentUpload.aspx?dir=doc&ext=jpg,jpeg,gif,png" upimgext="jpg,jpeg,gif,png"
                    upflashurl="/SystemManage/Common/ContentUpload.aspx?dir=doc&ext=swf" upflashext="swf"
                    upmediaurl="/SystemManage/Common/ContentUpload.aspx?dir=doc&ext=avi" upmediaext="avi">
            </textarea>
               </dd>
        </dl>  <dl class="nowrap">
                    <dt>&nbsp;</dt>
                    <dd> </dd>
        </dl>

                <input id="Id" type="hidden" />
                <!--sku组-->
                <fieldset>
                    <legend> 定制属性 : </legend>
                    <div class="checklist">
                         <a id="addsku" class="button sku" href="javascript:void(0);" title="SKU组-添加" max="false"
                            mask="true" minable="false" width="500" height="300"><span>添加</span></a>
                            <input id="hid_sku_groups" type="hidden"/>
                   <dl id="sku_groups" class="nowrap"  >
                    <!--属性列表-->
                </dl>
                    </div>
                    </fieldset>
                
                <!--搜索分类属性-->
                   <fieldset>
                    <legend> 搜索分类属性 : </legend>
                    <div class="checklist">
                         <a id="a_add_search_property" class="button " href="javascript:void(0);" title="搜索属性-添加" max="false"  mask="true" minable="false" width="500" height="300"><span>添加</span></a>
                   <dl id="dl_search_property_item" class="nowrap">
                    <!--属性列表-->
                </dl>
                    </div>
                    </fieldset>
                     
            </div>
            <div class="formBar">
                <ul>
                    <li>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button onclick="submitMenuItem();" type="button">
                                    提交</button></div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <script type="text/javascript">

            function clearGridList() {
                var strNone = ' <tr><td colspan="5" height="20px"></td></tr>';
                $('#grid_list', navTab.getCurrentPanel()).empty();
                $('#grid_list', navTab.getCurrentPanel()).append(strNone);
            }
            function submitMenuItem() {
                //alertMsg.confirm("请确认提交", {
                //   okCall: function () {


                $.get("/SystemManage/Basics/ProductCategory/CategoryInterface.aspx", { opt: "update_ex", Id: $("#Id", navTab.getCurrentPanel()).val(),
                    CategoryName: $("#Name", navTab.getCurrentPanel()).val(),
                    Sort: $("#Sort", navTab.getCurrentPanel()).val(),
                    ImgUrl: $("#fc_open_value_json", navTab.getCurrentPanel()).val(),
                    AttachmentUrl: $("#fc_relatedimgs_grid_json", navTab.getCurrentPanel()).val(),
                    ShortDesc: $("#ShortDesc", navTab.getCurrentPanel()).val(),
                    IsHot: ($("#IsHot", navTab.getCurrentPanel()).attr("checked") == false ? "0" : "1"),
                    IsActive: ($("#IsActive", navTab.getCurrentPanel()).attr("checked") == false ? "0" : "1"),
                    temp: new Date().valueOf()
                }, function () {
                    alertMsg.correct("操作成功");
                    _currentNode.Sort = $("#Sort", navTab.getCurrentPanel()).val();
                    _currentNode.CategoryDesc = $("#ShortDesc", navTab.getCurrentPanel()).val();
                    _currentNode.ImgUrl = $("#fc_open_value_json", navTab.getCurrentPanel()).val();
                    _currentNode.AttachmentUrl = $("#fc_relatedimgs_grid_json", navTab.getCurrentPanel()).val();
                    _currentNode.ShortDesc= $("#ShortDesc", navTab.getCurrentPanel()).val();
                    _currentNode.IsActive = ($("#IsActive", navTab.getCurrentPanel()).attr("checked") == false ? "0" : "1");
                    _currentNode.IsHot = ($("#IsHot", navTab.getCurrentPanel()).attr("checked") == false ? "0" : "1");
                });
                // }
                //});
            }
        </script>
    </div>
</div>
